package com.lj.cloudDisk.controller;


import com.lj.cloudDisk.config.exception.SpaceException;
import com.lj.cloudDisk.pojo.UcenterMember;
import com.lj.cloudDisk.pojo.dao.RegisterVo;
import com.lj.cloudDisk.pojo.dao.UcenterMemberDao;
import com.lj.cloudDisk.service.UcenterMemberService;
import com.lj.cloudDisk.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 用户
 */
@RestController
@Api(value = "用户管理接口",tags = "用户管理接口")
@RequestMapping("/user")
@CrossOrigin
public class UcenterMemberController  {


    @Autowired
    private UcenterMemberService ucenterMemberService;

    @ApiOperation(value = "登录")
    @PostMapping("/login")
    public R loginUser(@RequestBody UcenterMemberDao ucenterMember){

        Map<String, Object> map= ucenterMemberService.login(ucenterMember);

        return  R.success().data(map);
    }

    //注册
    @ApiOperation(value = "注册")
    @PostMapping("/register")
    public R registerUser(@RequestBody  @Validated RegisterVo registerVo) {
        ucenterMemberService.register(registerVo);
        return R.success();
    }

    //获取用户信息
    @ApiOperation(value = "获取用户信息")
    @GetMapping("/getUserInfo/{id}")
    public R getUserInfo(@PathVariable @Validated String id){

        UcenterMember userInfo = null;
        try {
            userInfo = ucenterMemberService.getUserInfo(id);
            return R.success().data("member",userInfo);
        } catch (Exception e) {
            throw new SpaceException(20001,"获取信息失败，未知错误");
        }


    }


}
